class Student:
    def __init__(self, student_list):
        self.student = student_list

    # 魔法函数(数据模型)：对当前类进行功能拓展

    # __getitem__或者__iter__使类可被迭代，变成可迭代类型，使类可直接循环遍历，item代表索引 从0开始
    def __getitem__(self, item):
        return self.student[item]

    def __len__(self):
        return len(self.student)


student = Student(["张三", "李四", "王五"])

print(type(student))

student_1 = student[:2]
print(type(student_1))  # list，因为__getitem__，当前类变成了可迭代类型

print(len(student_1))

print(len(student))  # __len__ 使类变成序列类型，才可以使用len(student)方法

for item in student:
    print(item)
